package com.cjst.controller.sys;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cjst.controller.base.BaseController;
import com.cjst.pojo.sys.SysCity;
import com.cjst.service.sys.SysCityService;
import com.cjst.sql.C;
import com.cjst.sql.Method;
import com.cjst.sql.WherePrams;

/**
 * 省市controller
 * @author szbj001
 *
 */
@Controller
@RequestMapping("/sys/sysCity")
public class SysCityController extends BaseController{
	
	
	@Autowired
	private SysCityService cityService;
	
	/**
	 * 查询省列表
	 * @return
	 */
	@RequestMapping(value="/getProvinces",method = RequestMethod.POST)
	@ResponseBody
	public Object getProvinces(){
		WherePrams prams = Method.where("fatherCode", C.EQ, "0");
		List<SysCity> provinces = cityService.list(prams);
		return provinces;
	}
	
	/**
	 * 根据省级编码查询下属市
	 * @param provinceCode
	 * @return
	 */
	@RequestMapping(value="/getCitysByProvince",method = RequestMethod.POST)
	@ResponseBody
	public Object getCitysByProvince(String provinceCode){
		if(StringUtils.isNotEmpty(provinceCode)){
			WherePrams prams = Method.where("fatherCode", C.EQ, provinceCode);
			List<SysCity> citys = cityService.list(prams);
			return citys;
		}
		return null;
	}
}
